﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Criterion;
using NHibernate.SqlCommand;
using NHibernateMappingSample.Entities;
using ProjectBase.Data.NHibernate;
using RepositorySample.Interfaces;

namespace RepositorySample.DataAccess
{

   public class OrdersRepository : GenericDao<SalesOrderHeader>, IOrdersRepository
   {
      
      public IList<SalesOrderHeader> GetOrdersForCustomer(int customerID)
      {
           DetachedCriteria query = DetachedCriteria.For<SalesOrderHeader>();
            query.CreateAlias("BelongsToCustomer", "customer", JoinType.InnerJoin).
               Add(Expression.Eq("customer.CustomerID", customerID));
            ICriteria criteria = query.GetExecutableCriteria(Session);

            return criteria.List < SalesOrderHeader>();
      }
   }
}
